<?php require_once('includes/config.php');
ob_start();
session_start();

$success = 0;
$s = 0;
if (isset($_GET['s']))
{
	$success = 1;
	$s = 1;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Simple Customer:  Installation</title>
<link href="includes/simplecustomer.css" rel="stylesheet" type="text/css" />
</head><body><div class="logincontainer" id="installcontainer"><h1><span class="loginheading">Simple Customer Installation</span></h1>
<?php if ($s!=1) { ?><form id="form1" name="form1" method="post" action="">
    <p>Your email address<br />
      <input name="email" type="text" id="email" size="35" />
</p>
    <p></p>
    <p>Choose a password <br />
      <input name="password" type="password" id="password" />
</p>
    <p></p>
    <input type="submit" name="Submit" value="Submit" />
  </form>
<?php } ?>
  <h1>
    <?php
    if ($_POST['email'] && $success==0)
    {
		//
		// Delete domains first for convenience
		//
		$sdb->deleteDomain('contacts');
		$sdb->deleteDomain('history');
		$sdb->deleteDomain('users');
		$sdb->deleteDomain('notes');

		$sdb->createDomain('contacts');
		$sdb->createDomain('notes');
		$sdb->createDomain('history');
		$sdb->createDomain('users');

		$id = uniqid();
		$level = 1;
		$email = trim($_POST['email']);
		$password = trim($_POST['password']);
		$date = time();
		$home = 'index.php';

		$attributes = array("user_id" 		=> array("value" => $id, 		"replace" => "true"),
							"user_level" 	=> array("value" => $level, 	"replace" => "true"),
							"user_email" 	=> array("value" => $email, 	"replace" => "true"),
							"user_password" => array("value" => $password, 	"replace" => "true"),
							"user_date" 	=> array("value" => $date, 		"replace" => "true"),
							"user_home" 	=> array("value" => $home, 		"replace" => "true"));

		$sdb->putAttributes('users', $id, $attributes);

		$_SESSION['user'] = $_POST['email'];

		header('Location: install.php?s'); die;
    }
	if ($success==1)
	{
		$query_usercheck = "SELECT * FROM users ";
		$row_usercheck = $sdb->select('users', $query_usercheck);
		$totalRows_usercheck = count($row_usercheck);

		if ($totalRows_usercheck > 0)
		{
			$success = 1;
		}
?>
	Installation Successful!  Please delete install.php and <a href="index.php" class="links">proceed to login.</a></h1>
<?php
	}
?>
</div>
</body>
</html>







